//
//  DouyinApiProvider.swift
//  ios_swift_demo1
//
//  Created by liutao on 2020/7/17.
//  Copyright © 2020 lt. All rights reserved.
//

import Foundation
import Moya
import RxSwift


//LoadingPlugin 加载圈
let DYApiProviderAndLoading = MoyaProvider<DYApiManager>(plugins:[LoadingPlugin])

let DYApiProvider = MoyaProvider<DYApiManager>(plugins:[NetworkLoggerPlugin(verbose: true)])

enum DYApiManager {
    //获取抖音视频列表
    case getTrillData(minId: Int,catId:Int)
}

extension DYApiManager: TargetType {
    var headers: [String : String]? {
        return nil
    }
    
    var baseURL: URL {
        return URL(string: "http://v2.api.haodanku.com/")!
    }
    
    var path: String {
        switch self {
        case .getTrillData(let minId,let catId):
            return "get_trill_data/apikey/xthdk/min_id/\(minId)/back/20/cat_id/\(catId)"
        }
    }
    
    var method: Moya.Method {
        return .get
    }
    
    //请求任务事件，附带上请求的参数
    var task: Task {
        switch self {
        case .getTrillData:
            return .requestPlain
        }
    }
    
    //这个就是做单元测试模拟的数据，只会在单元测试文件中有作用
    var sampleData: Data { return "".data(using: String.Encoding.utf8)! }
}



